package yxy.cherry.battle;

import yxy.cherry.battle.module.PropertyData;
import yxy.cherry.battle.module.PropertyType;
import yxy.cherry.data.DataCenter;
import yxy.cherry.data.bean.herodata;

import static yxy.cherry.battle.module.affix.Affix.VALUE_比率分母;

public class BattleFomula {

    // 物理防御减伤

    /**
     * attack1为所受到物理伤害，pdefense物防数值
     */
    static public Double 物理原始伤害(double attack1, double pdefense) {
        return Math.ceil(Math.max(attack1 - pdefense, (attack1 * 0.1)));
    }

    // 法术防御减伤

    /**
     * attack2为所受到法术伤害，sefense法防数值
     */
    static public Double 法术原始伤害(double attack2, double sefense) {
        return Math.ceil(Math.max(attack2 - sefense, (attack2 * 0.1)));
    }

    // 暴击伤害

    /**
     * attack为伤害（物理或者法术）数值,addPer为增加的的暴击伤害比例
     */
    static public Double 暴击伤害(double attack, double addPer) {
        return attack * addPer;
    }

    // 暴击概率

    /**
     * herodata表中抗暴数值，antiriot为抗暴数值，strike为暴击数值
     */
    static public Double 暴击概率(double antiriot, double strike) {
        return Math.max((strike - antiriot), 0);
    }

    // 命中概率

    /**
     * 为herodata表中闪避数值，dodge对方闪避数值，fit自身命中数值
     */
    static public Double 命中概率(double dodge, double fit) {
        return Math.max((fit - dodge), 0);
    }

    // 控制概率增量

    /**
     * probability为skill表中控制数值，control对方抗控数值，resist自身控制数值
     */
    static public Double 控制概率(double control, double resist, double probability) {
        return Math.max((probability + (resist - control)), 0);
    }

    // 爆伤增伤百分比

    /**
     * 为herodata表中控制数值，burstdrop对方爆伤减免数值，burstdps自身爆伤数值
     */
    static public Double 爆伤增伤(double burstdrop, double burstdps) {
        return Math.max((burstdps - burstdrop), 0);
    }

    // 物理减伤

    /**
     * 为herodata表中数值，burstdrop对方物理免伤数值，pdefenseup自身物理增伤数值
     */
    static public Double 增伤(double burstdrop, double pdefenseup, double sburstdrop, double spdefenseup) {
        return (pdefenseup + spdefenseup - burstdrop - sburstdrop);
    }

    // 治疗增量

    /**
     * 为herodata表中数值，therapy对方受疗，treatment自身治疗
     */
    static public Double 治疗增量(double therapy, double treatment) {
        return (therapy + treatment);
    }

    // 战力计算

    /**
     * 攻击、物防、法防、生命、暴击、抗暴、暴伤、爆伤减免、
     * 命中、闪避、控制、抗控、初始怒气、治疗、受疗、物攻提升、法攻提升、
     * 物理减伤、法术减伤、技能等级
     */
    static public Double 战力(double attack, double pdefense, double sefense, double life, double strike, double antiriot, double burstdps, double burstdrop,
                            double fit, double dodge, double control, double resist, double initialanger, double treatment, double therapy, double pdefenseup, double pdefenseguard,
                            double sefenseup, double efenseguard, double skilldps,int id,double speed) {
        double power = Math.ceil((attack * 100 * (1 + pdefenseup / VALUE_比率分母 + strike * 0.5 / VALUE_比率分母 + burstdps * 0.5 / VALUE_比率分母))*(1+speed/2000)
                + (pdefense * 166 * (1 + pdefenseguard / VALUE_比率分母 + antiriot * 0.5 / VALUE_比率分母 + burstdrop * 0.5 / VALUE_比率分母))
                + (life * 17.8 * (1 + dodge / VALUE_比率分母 + treatment * 0.5 / VALUE_比率分母 + therapy * 0.5 / VALUE_比率分母 + control * 0.3 / VALUE_比率分母 + resist * 0.3 / VALUE_比率分母)));

        //神魔在原战力基础上增加30%，名将增加15%
        herodata _herodata = DataCenter.getData(id, herodata.class);
        if(_herodata.getAptitude()==22) power = power * 1.15;

        return power / 9;
    }

    static public long 战力(PropertyData propertyData,int id) {
        return 战力(propertyData.getValue(PropertyType.P_攻击), propertyData.getValue(PropertyType.P_防御), propertyData.getValue(PropertyType.P_法防),
                propertyData.getValue(PropertyType.P_生命), propertyData.getValue(PropertyType.P_暴击), propertyData.getValue(PropertyType.P_抗暴),
                propertyData.getValue(PropertyType.P_暴伤), propertyData.getValue(PropertyType.P_韧性), propertyData.getValue(PropertyType.P_命中),
                propertyData.getValue(PropertyType.P_闪避), propertyData.getValue(PropertyType.P_控制), propertyData.getValue(PropertyType.P_抗控), 0,
                propertyData.getValue(PropertyType.P_治疗), propertyData.getValue(PropertyType.P_受疗), propertyData.getValue(PropertyType.P_增伤),
                propertyData.getValue(PropertyType.P_减伤), propertyData.getValue(PropertyType.P_法增), propertyData.getValue(PropertyType.P_法减),
               0,id, propertyData.getValue(PropertyType.P_速度增幅)).longValue();
    }

    // 武将升级攻击属性提升

    /**
     * lv为武将等级，attack为herograde表攻击提升参数
     */
    static public long 武将升级攻击属性提升(int lv, int attack) {
        long value = genValue(lv, attack);
        return value;
    }


    // 武将升级物防属性提升

    /**
     * lv为武将等级，pdefense为herograde表物防提升参数
     */
    static public long 武将升级物防属性提升(int lv, int pdefense) {
        long value = genValue(lv, pdefense);
        return value;
    }

    // 武将升级法防属性提升

    /**
     * lv为武将等级，sefense为herograde表物防提升参数
     */
    static public long 武将升级法防属性提升(int lv, int sefense) {
        long value = genValue(lv, sefense);
        return value;
    }

    // 武将升级生命属性提升

    /**
     * lv为武将等级，life为herograde表物防提升参数
     */
    static public long 武将升级生命属性提升(int lv, int life) {
        long value = genValue(lv, life);
        return value;
    }


    /**
     * lv为武将等级，speed为herograde表速度提升参数
     */
    static public long 武将升级速度属性提升(int lv, int speed) {
        long value = lv * speed;
        return value;
    }

    /**
     * 根据公式计算值
     *
     * @param value
     * @return
     */
    private static long genValue(int lv, int value) {
        if (lv <= 80) {
            return lv * value * 3;
        }
        if (lv <= 220) {
            return (80 * value * 3) + ((lv - 80) * (value * 4));
        }
        if (lv <= 280) {
            return (80 * value * 3) + (140 * value * 4) + ((lv - 220) * (value * 6));
        }
        if (lv <= 340) {
            return (80 * value * 3) + (140 * value * 4) + (60 * value * 6) + ((lv - 280) * (value * 7));
        }
        return (80 * value * 3) + (140 * value * 4) + (60 * value * 6) + ((lv - 280) * (value * 7));
    }
}
